package com.michael.redis.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.michael.redis.object.User;
import com.michael.redis.service.IUserService;

@RestController
@RequestMapping("/user")
public class UserController {

	@Autowired
	private IUserService userService;

	@RequestMapping("/getOne")
	public User getOne(Long id) {

		return userService.getOne(id);
	}

	@RequestMapping("/getAll")
	public List<User> getAll() {
		// 先查缓存，再查数据库
		return userService.getAll();
	}


	@RequestMapping("/save")
	public User save(@RequestBody User user) {
		// 将返回值存入缓存
		return userService.save(user);
	}


	@RequestMapping("/del")
	public void del(Long id) {
		//将缓存清除
		userService.del(id);
	}

}
